package src.LLVM.mem;

import src.LLVM.IR;

public class AllocaIR implements IR {
    private final String reg;
    private String x = "";
    private String y = "";
    static String operation = "alloca";
    public AllocaIR(String reg){
        this.reg = reg;
    }
    public AllocaIR(String reg, String dim1){
        this.x = dim1;
        this.reg = reg;
    }
    public AllocaIR(String reg, String dim1,String dim2){
        this.x = dim1;
        this.y = dim2;
        this.reg = reg;
    }
    @Override
    public String toString(){
        String tab = "\t";
        if (x.length() == 0 && y.length() == 0){
            return tab + reg + " = " + operation + " i32";
        }else if(x.length() != 0 && y.length() != 0){
            //int size = Integer.parseInt(x) * Integer.parseInt(y);
           // return tab + reg + " = " + operation + " [" + size + " x i32] ;";
            return tab + reg + " = " + operation + " [" + x +" x [" + y + " x i32]]";
        }else if(x.length() != 0) {
            return tab + reg + " = " + operation + " [" + x + " x i32] ;";
        }
        return "";
    }
}
